//
//  ZJPublicFormAreatTableViewCell.m
//  ZJControlsClass
//
//  Created by mac on 2024/11/28.
//

#import "ZJPublicFormAreatTableViewCell.h"

@interface ZJPublicFormAreatTableViewCell ()

@property (nonatomic,strong) UIView * v;



@end


@implementation ZJPublicFormAreatTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        [self configUI];
        
        
        
    }
    return self;
}


-(void)configUI{
    
    [self.contentView addSubview:self.requiredLabel];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.inputTextF];
    [self.contentView addSubview:self.rightImg];
    [self.contentView addSubview:self.v];
    
    
    
    [self.contentView sd_addSubviews:@[self.requiredLabel ,self.titleLabel,self.inputTextF,self.rightImg,self.v]];
    
    
    self.requiredLabel.sd_layout
        .leftSpaceToView(self.contentView, ALIGN_WIDTH_PT(15))
        .topSpaceToView(self.contentView, 0)
        .widthIs(10)
        .heightIs(ALIGN_HEIGHT_PT(50));
    
    
    self.titleLabel.sd_layout
    .leftSpaceToView(self.requiredLabel, ALIGN_WIDTH_PT(0))
    .topSpaceToView(self.contentView, 0)
    .widthIs(SCREEN_WIDTH / 2 - ALIGN_WIDTH_PT(15))
    .heightIs(ALIGN_HEIGHT_PT(50));
    
    self.inputTextF.sd_layout
    .leftSpaceToView(self.titleLabel, 0)
    .rightSpaceToView(self.contentView, ALIGN_WIDTH_PT(15))
    .topEqualToView(self.titleLabel)
    .heightIs(50);
    
    self.rightImg.sd_layout
    .rightSpaceToView(self.contentView, ALIGN_WIDTH_PT(10))
    .centerYEqualToView(self.inputTextF)
    .widthIs(6)
    .heightIs(10);

    self.v.sd_layout
    .leftSpaceToView(self.contentView, ALIGN_WIDTH_PT(10))
    .rightSpaceToView(self.contentView, ALIGN_WIDTH_PT(10))
    .topSpaceToView(self.titleLabel, 1)
    .heightIs((1));
    
    
    
}

-(void)setModel:(HomeUnitModel *)model{
    _model = model;
    
    
    if ([model.props.required boolValue] == YES) {
        self.requiredLabel.hidden = NO;
    }else{
        self.requiredLabel.hidden = YES;
    }
    
    
    self.titleLabel.text = model.props.title;
    
    if ([model.props.placeholder isEqualToString:@"请选择区域"]){
        self.inputTextF.textColor = [UIColor grayColor];
        self.inputTextF.text = self.model.props.placeholder;

        self.inputTextF.sd_layout
            .heightIs(ALIGN_HEIGHT_PT(50));
        
        self.v.sd_layout
            .topSpaceToView(self.inputTextF, 0);
        
    }else{
        self.inputTextF.textColor = [UIColor blackColor];
        
        // 计算高度
        NSMutableAttributedString * attriBedString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",self.model.props.input]];
        UIFont * font = FONT14;
        NSMutableParagraphStyle * style = [[NSMutableParagraphStyle alloc]init];
        style.lineSpacing = ALIGN_HEIGHT_PT(5);
        [attriBedString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, self.model.props.input.length)];
        [attriBedString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, self.model.props.input.length)];
        self.inputTextF.attributedText = attriBedString;
        
        
        NSStringDrawingOptions  options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
        CGFloat lableSize = [attriBedString boundingRectWithSize:CGSizeMake(SCREEN_WIDTH / 2 - ALIGN_WIDTH_PT(30), MAXFLOAT) options:options context:nil].size.height;
        
        if (lableSize < 50){
            
            self.inputTextF.sd_layout
                .heightIs(ALIGN_HEIGHT_PT(50));
            self.v.sd_layout
                .topSpaceToView(self.inputTextF, 0);
            
        }else{
            
            self.inputTextF.sd_layout
                .heightIs(lableSize);
            self.v.sd_layout
                .topSpaceToView(self.inputTextF, 10);
            
        }
        
    }
    
    [self setupAutoHeightWithBottomView:self.v bottomMargin:0];
    
    
}

#pragma mark -- 懒加载

-(UILabel *)requiredLabel{
    if (!_requiredLabel) {
        _requiredLabel = [UILabel new];
        _requiredLabel.text = @"*";
        _requiredLabel.textColor = [UIColor redColor];
        _requiredLabel.font = FONT14;
        _requiredLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _requiredLabel;
}

-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.text = @"申办单位全称";
        _titleLabel.font = FONT14;
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLabel;
}

-(UILabel *)inputTextF{
    if (!_inputTextF) {
        _inputTextF = [UILabel new];
        _inputTextF.textColor = [UIColor blackColor];
        _inputTextF.font = FONT14;
        _inputTextF.textAlignment = NSTextAlignmentLeft;
        _inputTextF.numberOfLines = 0;
    }
    return _inputTextF;
}

-(UIImageView *)rightImg{
    if (!_rightImg) {
        _rightImg = [UIImageView new];
        _rightImg.image = [UIImage imageNamed:@"Vector"];
    }
    return _rightImg;
}
-(UIView *)v{
    if (!_v) {
        _v = [UIView new];
        _v.backgroundColor = COLOR_RGB(215, 216, 217);
    }
    return _v;
}




@end
